package com.ruoyi.custom.kami.controller;

import cn.hutool.core.date.DateUtil;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.custom.kami.domain.CmsKami;
import com.ruoyi.custom.kami.service.ICmsKamiService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.apache.poi.ss.formula.functions.Now;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;

@Api(tags = "卡密管理-CmsKamiApiController", description = "")
@RestController
@RequestMapping("/app/api/cms")
public class CmsKamiApiController extends BaseController {

    @Autowired
    private ICmsKamiService cmsKamiService;

    @ApiOperation("获取卡密信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "cardPasswd", value = "卡密", dataType = "String", dataTypeClass = String.class)

    })
    @PutMapping("/getKamiInfo")
    public AjaxResult getKamiInfo(String cardPasswd) {
        CmsKami cmsKami = new CmsKami();
        cmsKami.setCardPasswd(cardPasswd);
        CmsKami callback = cmsKamiService.selectKaMiInfoByKamistr(cmsKami);
        if (callback == null) {
            return AjaxResult.error(1001,"卡密错误");
        }
        if (callback.getUsedTime() != null) {
            return AjaxResult.error(1002,"卡密已使用");
        }
        callback.setUsedTime(DateUtils.getNowDate());
        cmsKamiService.updateCmsKami(callback);
        return AjaxResult.success(callback);
    }

}
